#ifndef _HTML_H
#define _HTML_H

const char _HTML[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html lang="en"><head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>配置</title>
    <style>
        * {
            font-size: 16px;
        }
        body {
            margin: 0;
            padding: 0;
        }
        .panel {
            width: calc(100% - 20px);
            height: auto;
            margin: 10px;
            border-radius: 5px;
            border: 1px solid lightgray;
        }
        .row {
            width: 100%;
            padding: 5px;
        }
        .row > span {
            display: inline-block;
            width: 100%;
        }
        .row > input {
            width: calc(100% - 10px);
            padding: 7px;
        }
        .row > button {
            width: calc(100% - 10px);
            padding: 7px;
            margin-top: 15px;
        }
        #msg {
            color: darkorchid;
        }
    </style>
</head>
<body>
    <div class="panel">
        <form>
            <div class="row">
                <span>WiFi名称</span>
                <input type="text" name="ssid" id="ssid">
            </div>
            <div class="row">
                <span>WiFi密码</span>
                <input type="text" name="pwd" id="pwd">
            </div>
            <div class="row">
                <button type="button" onclick="config()">提交</button>
            </div>
            <div class="row">
                <button type="button" onclick="ctrlPin(0, 1)">打开引脚0</button>
            </div>
            <div class="row">
                <button type="button" onclick="ctrlPin(0, 0)">关闭引脚0</button>
            </div>
            <div class="row">
                <button type="button" onclick="ctrlPin(2, 1)">打开引脚2</button>
            </div>
            <div class="row">
                <button type="button" onclick="ctrlPin(2, 0)">关闭引脚2</button>
            </div>
            <p id="msg"></p>
        </form>
    </div>
    <script>
        function config() {
            var ssid = document.getElementById("ssid").value;
            var pwd  = document.getElementById("pwd").value;
            fetch("/config?ssid="+ssid+"&pwd="+pwd)
            .then(res=>res.text()).then((res)=>{
                document.getElementById("msg").innerText = res;
            }).catch(error=>{
                document.getElementById("msg").innerText = "请求失败："+error;
            });
        }
        function ctrlPin(pin, val) {
            var onOff = (val==1) ? "on" : "off";
            fetch ("/output?pin="+pin+"&val="+onOff)
            .then(res=>res.text()).then((res)=>{
                document.getElementById("msg").innerText = res;
            }).catch(error=>{
                document.getElementById("msg").innerText = "请求失败："+error;
            });
        }
    </script>
</body></html>
)rawliteral";

#endif //_HTML_H
